package com.lishu.carsafe.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lishu.carsafe.R;
import com.lishu.carsafe.model.entity.Type;

import java.util.ArrayList;
import java.util.List;


public class TypeListAdapter extends BaseAdapter {
        private LayoutInflater mInflater;
        private Context mContext;
        private List<Type> optionList = new ArrayList<Type>();
        private int clickedItem = -1;

        //标识选择的Item
        public void setSeclection(int position) {
            clickedItem = position;
        }

        public TypeListAdapter(Context context){
            this.mContext = context;
            mInflater = LayoutInflater.from(mContext);
        }

        public void setData(List<Type> optionList){
            this.optionList = optionList;
            notifyDataSetChanged();
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return optionList.size();
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            if (optionList.size() > 0) {
                return optionList.get(position);
            } else {
                return null;
            }
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            ViewHolder holder = null;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = mInflater.inflate(R.layout.layout_listview_item, null);
                holder.name = (TextView)convertView.findViewById(R.id.name);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            holder.name.setText(optionList.get(position).getParamName());

            return convertView;
        }

        static class ViewHolder {
            private TextView name;
        }
    }
